package com.cjzuji.rental.controller.tool;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.cjzuji.rental.mapper.UserMapper;
import com.cjzuji.rental.pojo.UserData;
import com.cjzuji.rental.service.impl.UserServiceImpl;
import lombok.val;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/tool/user")
public class UserController {

    @Autowired
    UserServiceImpl userServiceimpl;
    @Autowired
    UserMapper userMapper;
    //添加
    @PostMapping  // http://127.0.0.1:9099/tool/user
    public String userdata(@RequestBody UserData userData) {
        System.out.println("加入了");
        userServiceimpl.add(userData);

        return "success!";
    }

    // 请求外部接口将数据保存到数据库中
    @GetMapping("/external")
    public String externalUserData() {
        System.out.println("请求外部接口");
        userServiceimpl.external();
        return "success!";
    }

    // 通过id查询详情
    @GetMapping("/{id}")
    public Map<String, Object> getUserById(@PathVariable Long id) {
        UserData userData = userServiceimpl.getUserById(id);
        HashMap<String, Object> map = new HashMap<>();
        map.put("user", userData);
        map.put("massage", "success");
        map.put("code", 200);
        return map;
    }


}
